import type { ISectionDetails } from '@/interfaces';
import Link from 'next/link';
import { SECTION_OTHER_STATE_KEY, SECTION_STATE_KEY } from '@/lib/constant';
import { formatDate } from '@/lib/tool';

export default function QuerySectionInfo({
  details,
}: {
  details: ISectionDetails;
}) {
  return (
    <div className="row">
      <div className="col">
        <div className="card">
          <div className="card-header bg-transparent text-muted">
            <i className="bi bi-info-square me-2"></i>
            <Link
              href={`/sections/${details.basic.id}`}
              className="link-dark text-decoration-none text-decoration-underline-hover"
            >
              {details.basic.name}
            </Link>
          </div>
          <div className="card-body">
            <div className="table-responsive">
              <table className="table table-hover align-middle table-striped">
                <thead>
                  <tr className="text-nowrap">
                    <th scope="col" className="fw-normal">
                      ID
                    </th>
                    <th scope="col" className="fw-normal">
                      {details.basic.id}
                    </th>
                  </tr>
                </thead>
                <tbody>
                  {Object.keys(details.basic)
                    .filter((item) => !['id'].includes(item))
                    .map((item) => {
                      return (
                        <tr key={item} className="text-nowrap">
                          <td>
                            {item === 'createdBy' && '创建用户'}

                            {item === 'updatedBy' && '更新用户'}

                            {item === 'creatorAlias' && '创建者别名'}

                            {item === 'updaterAlias' && '更新者别名'}

                            {item === 'createdOn' && '创建时间'}

                            {item === 'updatedOn' && '更新时间'}

                            {item === 'deleted' && '是否删除'}

                            {item === 'name' && '版块名称'}

                            {item === 'overview' && '版块概述'}

                            {item === 'cover' && '版块封面'}

                            {item === 'sort' && '排序'}

                            {item === 'state' && '状态'}

                            {item === 'otherStates' && '其他状态'}

                            {item === 'allow' && '白名单'}

                            {item === 'block' && '黑名单'}
                          </td>
                          <td>
                            {item === 'createdBy' && details.basic[item]}

                            {item === 'updatedBy' && details.basic[item]}

                            {item === 'creatorAlias' && details.basic[item]}

                            {item === 'updaterAlias' && details.basic[item]}

                            {item === 'createdOn' &&
                              formatDate(details.basic[item])}

                            {item === 'updatedOn' &&
                              formatDate(details.basic[item])}

                            {item === 'deleted' && details.basic[item] + ''}

                            {item === 'name' && details.basic[item]}

                            {item === 'overview' && details.basic[item]}

                            {item === 'cover' && details.basic[item]}

                            {item === 'sort' && details.basic[item]}

                            {item === 'state' &&
                              SECTION_STATE_KEY[details.basic[item]]}

                            {item === 'otherStates' &&
                              (details.basic[item].length === 0
                                ? ['DEFAULT']
                                : details.basic[item]
                              )
                                .map((value) => SECTION_OTHER_STATE_KEY[value])
                                .join(',')}

                            {item === 'allow' &&
                              details.basic[item]?.join(', ')}

                            {item === 'block' &&
                              details.basic[item]?.join(', ')}
                          </td>
                        </tr>
                      );
                    })}
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
